home *** CD-ROM | disk | FTP | other *** search
- /* stripfile.cpp
- *
- * This contains the actual strip code. There are two versions of this
- * file, one for the 68K version, and one for the PPC version
- */
-
- #include "Strip.h"
- #include "cfrg.h"
-
- /************************************************************************/
- /* */
- /* Error Display Code */
- /* */
- /************************************************************************/
-
- /* DisplayAlert
- *
- * Display the alert, given the application name and message
- */
-
- static void DisplayAlert(FSSpec *file, short id, short code)
- {
- unsigned char buffer[256];
- unsigned char codeStr[32];
-
- GetIndString(buffer,128,id);
- if (code) {
- NumToString(code,codeStr);
- ParamText(file->name,buffer,codeStr,NULL);
- } else {
- ParamText(file->name,buffer,NULL,NULL);
- }
- Alert(130,NULL);
- }
-
- /************************************************************************/
- /* */
- /* Main entry point */
- /* */
- /************************************************************************/
-
- /* StripFile
- *
- * Determine if this file is the correct one by type and temperment;
- * if it is, then go ahead and strip the code resources and replace them
- * with one that presents a very simple message.
- */
-
- void StripFile(FSSpec *file)
- {
- FInfo finfo;
- short appRefNum;
- short err;
- CFRGResource **cfrg;
-
- /*
- * Figure out what the file type is.
- */
-
- if (FHasFSSpec) FSpGetFInfo(file,&finfo);
- else HGetFInfo(file->vRefNum,file->parID,file->name,&finfo);
-
- if (finfo.fdType != 'APPL') {
- DisplayAlert(file,1,0);
- return;
- }
-
- /*
- * Now open this application for modification.
- */
-
- if (FHasFSSpec) appRefNum = FSpOpenResFile(file,fsRdWrPerm);
- else appRefNum = HOpenResFile(file->vRefNum,file->parID,file->name,fsRdWrPerm);
- if (appRefNum == -1) {
- DisplayAlert(file,2,0);
- return;
- }
-
- /*
- * Is there a code fragment resource?
- */
-
- cfrg = (CFRGResource **)Get1Resource('cfrg',0);
- if (cfrg == NULL) {
- CloseResFile(appRefNum);
- DisplayAlert(file,3,0);
- return;
- }
- if (((**cfrg).version != 1) || ((**cfrg).numFrags != 1) ||
- ((**cfrg).frags[0].type != 'pwpc') || ((**cfrg).frags[0].usage != 1) ||
- ((**cfrg).frags[0].loc != 1) || ((**cfrg).frags[0].offset != 0) ||
- ((**cfrg).frags[0].length != 0)) {
-
- ReleaseResource((Handle)cfrg);
- CloseResFile(appRefNum);
- DisplayAlert(file,4,0);
- return;
- }
-
- /*
- * Remove the fragment resource.
- */
-
- SetResAttrs((Handle)cfrg,0);
- RemoveResource((Handle)cfrg);
- if (0 != (err = ResError())) {
- ReleaseResource((Handle)cfrg);
- CloseResFile(appRefNum);
- DisplayAlert(file,5,err);
- return;
- }
-
- UpdateResFile(appRefNum);
- CloseResFile(appRefNum);
-
- if (FHasFSSpec) FSpOpenDF(file,fsRdWrPerm,&appRefNum);
- else HOpen(file->vRefNum,file->parID,file->name,fsRdWrPerm,&appRefNum);
- SetEOF(appRefNum,0L); // Clear the current EOF
- FSClose(appRefNum);
- }
-
-